import 'package:fate_blind_box/config/app_style.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:intl/intl.dart';

Future<bool?> showCommonDialog(
    {required BuildContext context,
    String? title,
    String? content,
    String? positiveContent,
    String? navigateContent}) async {
  assert(title != null || content != null);
  return showCupertinoDialog(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return CupertinoAlertDialog(
          title: title != null
              ? Text(
                  title,
                  style: const TextStyle(fontSize: 17),
                )
              : null,
          content: content != null
              ? Text(
                  content,
                  style:  TextStyle(
                      fontSize: 13, color: '333333'.stringToColor),
                )
              : null,
          actions: [
            CupertinoDialogAction(
                onPressed: () {
                  Navigator.of(context).pop(false);
                },
                child: Text(
                  navigateContent ?? '取消',
                  style:  TextStyle(
                      fontSize: 17, color:'666666'.stringToColor),
                )),
            CupertinoDialogAction(
                onPressed: () {
                  Navigator.of(context).pop(true);
                },
                child: Text(
                  positiveContent ?? '确定',
                  style:  TextStyle(
                      fontSize: 17, color: '007aff'.stringToColor),
                ))
          ],
        );
      });
}

Future<T?> showBottomChoose<T>(
    {required BuildContext context,
    required List<CupertinoActionSheetAction> actions,
    Widget? title,
    Widget? message,
    bool showCancel = true}) async {
  return showCupertinoModalPopup<T>(
      context: context,
      barrierColor: const Color(0x66000000),
      builder: (BuildContext context) {
        return CupertinoActionSheet(
          title: title,
          message: message,
          cancelButton: showCancel
              ? CupertinoActionSheetAction(
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                  child: Text(
                    '取消',
                    style: TextStyle(
                        fontSize: 16, color: '333333'.stringToColor),
                  ),
                )
              : null,
          actions: actions
              .map((e) => Container(
                    color: Colors.white,
                    child: e,
                  ))
              .toList(),
        );
      });
}

void showDateTimePicker(
    BuildContext context, String? initTime, ValueChanged<String> onSelect) {
  DateFormat _format = DateFormat('yyyy-MM-dd');
  String pickTime = initTime ?? _format.format(DateTime.now());
  showCupertinoModalPopup(
      context: context,
      builder: (context) => Container(
            color: Colors.white,
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Row(
                  children: [
                    TextButton(
                        onPressed: () {
                          Navigator.pop(context);
                        },
                        child: const Text('取消')),
                    const Expanded(child: SizedBox()),
                    TextButton(
                        onPressed: () {
                          onSelect(pickTime);
                          Navigator.pop(context);
                        },
                        child: const Text('确定')),
                  ],
                ),
                 Divider(
                  height: 1.w,
                  color: '666666'.stringToColor,
                ),
                SizedBox(
                  height: 229,
                  child: CupertinoDatePicker(
                    mode: CupertinoDatePickerMode.date,
                    minimumDate: DateTime(1900, 1, 1, 0, 0),
                    maximumDate: DateTime.now(),
                    initialDateTime: DateTime.parse(pickTime),
                    onDateTimeChanged: (dateTime) {
                      pickTime = _format.format(dateTime);
                    },
                  ),
                )
              ],
            ),
          ));
}
